<template>
    <div>
      <el-card>

        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
          <el-form-item label="商品编码" prop="productCore">
            <el-input
              v-model="queryParams.productCore"
              placeholder="请输入商品编码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="商品名称" prop="productName">
            <el-input
              v-model="queryParams.productName"
              placeholder="请输入商品名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>



          <el-form-item label="上下架状态" prop="publishStatus">
            <el-select v-model="queryParams.publishStatus" placeholder="请选择上下架状态" clearable size="small">
              <el-option label="下架" value="1" />
              <el-option label="上架" value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="审核状态" prop="auditStatus">
            <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable size="small">
              <el-option label="未审核" value="1" />
              <el-option label="已审核" value="0" />
            </el-select>
          </el-form-item>







          <el-form-item>
            <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="warning"
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" border @row-dblclick="shuangjiya" :data="infoList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="商品ID" align="center" prop="productId" />
          <el-table-column label="商品编码" align="center" prop="productCore" />
          <el-table-column label="商品名称" align="center" prop="productName">
            <!--<template slot-scope="scope">-->
              <!--<router-link :to="'/supergoods/type/superorder/' + scope.row.productId" class="link-type">-->
                <!--<span>{{ scope.row.productName }}</span>-->
              <!--</router-link>-->
            <!--</template>-->
          </el-table-column>
          <el-table-column label="商品销售价格" align="center" prop="price" />
          <el-table-column label="商品加权平均成本" align="center" prop="averageCost" />
          <el-table-column label="上下架状态" align="center" prop="publishStatus">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.publishStatus === 1 ? 'primary' : 'success'"
                disable-transitions>{{scope.row.publishStatus ===1 ? '下架' : '上架'}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="审核状态" align="center" prop="auditStatus" width="200px" >
            <template slot-scope="scope">
              <el-switch v-model="scope.row.auditStatus"  active-text="已审核" inactive-text="未审核" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
            </template>
          </el-table-column>
          <!--<el-table-column label="商品重量" align="center" prop="weight" />-->
          <!--<el-table-column label="商品长度" align="center" prop="length" />-->
          <!--<el-table-column label="商品高度" align="center" prop="height" />-->
          <!--<el-table-column label="商品宽度" align="center" prop="width" />-->
          <!--<el-table-column label="商品颜色" align="center" prop="colorType" />-->
          <el-table-column label="生产日期" align="center" prop="productionDate" width="130">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="商品有效期" align="center" prop="shelfLife" />
          <el-table-column label="商品描述" align="center" prop="descript" />
          <el-table-column label="商品录入时间" align="center" prop="indate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.indate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </el-card>
    </div>
</template>

<script>
  import {  superSuppgetInfo, superProductList, superProexport,changeauditStatus } from "@/api/super/goodsstore";
    export default {
        name: "supergoods",
      data(){
        return {
          // 遮罩层
          loading: true,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 商品信息表格数据
          infoList: [],
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            productCore: null,
            productName: null,
            barCode: null,
            brandId: null,
            oneCategoryId: null,
            twoCategoryId: null,
            threeCategoryId: null,
            supplierId: null,
            categoryId: null,
            price: null,
            averageCost: null,
            publishStatus: null,
            auditStatus: null,
            weight: null,
            length: null,
            height: null,
            width: null,
            colorType: null,
            productionDate: null,
            shelfLife: null,
            descript: null,
            indate: null,
            modifiedTime: null,
            cornerQuantity: null,
            labelName: null,
            salesQuantity: null,
          },
          defaultDictType: "",
          // 表单参数
          form: {},

          }
      },

      created() {
        const supplierId = this.$route.params && this.$route.params.supplierId;
        // console.log("**********"+supplierId)
        this.superSuppgetInfo(supplierId);
        // this.getList();
      },
      methods: {
        handleStatusChange(row){
          let text = row.auditStatus === "0" ? "已审核" : "未审核";
          this.$confirm(
            '确认要"' + text + '""' + row.productName + '"商品吗?',
            "警告",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
            .then(function () {
              return changeauditStatus(row.productId, row.auditStatus);
            })
            .then(() => {
            this.msgSuccess(text + "成功");
        })
        .catch(function () {
            row.auditStatus = row.auditStatus === "0" ? "1" : "0";
          });
        },
        shuangjiya(row){
          this.$router.push({
            path:"/supergoods/type/superorder/",
            query:{
              productId: row.productId,
            }
          })
        },

        superSuppgetInfo(supplierId){
          superSuppgetInfo(supplierId).then(res=>{
              this.queryParams.supplierId = res.data.supplierId;
          this.defaultDictType = res.data.categoryId;
          this.getList();
          })
        },
        /** 查询商品信息列表 */
        getList() {
          this.loading = true;
          superProductList(this.queryParams).then(response => {
            this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
        },
        // 取消按钮
        cancel() {
          this.open = false;
          this.reset();
        },
        // 表单重置
        reset() {
          this.form = {
            productId: null,
            productCore: null,
            productName: null,
            barCode: null,
            brandId: null,
            oneCategoryId: null,
            twoCategoryId: null,
            threeCategoryId: null,
            supplierId: null,
            categoryId: null,
            price: null,
            averageCost: null,
            publishStatus: 0,
            auditStatus: 0,
            weight: null,
            length: null,
            height: null,
            width: null,
            colorType: null,
            productionDate: null,
            shelfLife: null,
            descript: null,
            indate: null,
            modifiedTime: null,
            cornerQuantity: null,
            labelName: null,
            salesQuantity: null,
            delFlag: null
          };
          this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
          this.ids = selection.map(item => item.productId)
          this.single = selection.length!==1
          this.multiple = !selection.length
        },

        /** 导出按钮操作 */
        handleExport() {
          const queryParams = this.queryParams;
          this.$confirm('是否确认导出所有商品信息数据项?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
            return superProexport(queryParams);
          }).then(response => {
            this.download(response.msg);
        }).catch(function() {});
        }

      }

    }
</script>

<style scoped>

</style>
